package com.sheep.taobao;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class JdbcUtil {
    private static Properties env=null;
	static{
		env=new Properties();
		try{
			InputStream in=JdbcUtil.class.getResourceAsStream("/env.properties");				
			env.load(in);
			in.close();
		}catch(Exception e){
			e.printStackTrace();
			throw new ExceptionInInitializerError(e);
			
		}
		
	}
    public static Connection getConnection() throws Exception{
		
		 //1 注册驱动 
		 Class.forName(env.getProperty("driver"));
		 
	     return DriverManager.getConnection(
	    		 env.getProperty("url"),
	    		 env.getProperty("uname"),
	    		 env.getProperty("pword"));
    }
	
	 
	public static void close(ResultSet rs,Statement stmt,Connection conn){
		    if(rs!=null){try{rs.close();}catch(Exception e){}}
	        if(stmt!=null){try{stmt.close();}catch(Exception e){}}
	        if(conn!=null){try{conn.close();}catch(Exception e){}}
		
	}
	 
}

